package com.ybwh.springboot1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ybwh.springboot1.common.RespData;
import com.ybwh.springboot1.model.vo.AreaVo;
import com.ybwh.springboot1.service.AreaService;

/**
 * <p>
 * 地区管理前端控制器
 * </p>
 *
 * @author saytime
 * @since 2018-12-06
 */
@Controller
@RequestMapping("/area")
public class AreaController {
	
	@Autowired
	private AreaService areaService;

	@ResponseBody
	@RequestMapping("/validate")
	public RespData<Object> validate(@Validated @ModelAttribute AreaVo areaVo, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			for(ObjectError error : bindingResult.getAllErrors()) {
				return RespData.failedResp(error.getDefaultMessage());
			}
		}

		return RespData.successResp(null);
	}
	
	
	@ResponseBody
	@RequestMapping("/queryPage")
	public RespData<Object> queryPage() {

		return RespData.successResp(areaService.queryPage());
	}

}
